#!/usr/bin/env python
# -*- coding: utf-8 -*-
from controls import data_user_feed_mysql
from controls import data_topic_note_mysql
from controls import data_topic_note_like_mysql
from controls import data_topic_like_mysql

def refresh():
    all_note_list = data_topic_note_mysql.get_all_topic_note()

    for note in all_note_list:
        data_user_feed_mysql.add_user_feed_item_with_time({
            'userid': note['userid'],
            'optype': data_user_feed_mysql.USER_FEED_TYPE_NOTE_POST,
            'targetid': note['noteid'],
            'ctime': note['ctime'],
        })

    all_note_like_list = data_topic_note_like_mysql.get_all_note_like()

    for note_like in all_note_like_list:
        data_user_feed_mysql.add_user_feed_item({
            'userid': note_like['userid'],
            'optype': data_user_feed_mysql.USER_FEED_TYPE_NOTE_LIKE,
            'targetid': note_like['noteid'],
        })

    all_topic_like_list = data_topic_like_mysql.get_all_topic_like()

    for topic_like in all_topic_like_list:
        data_user_feed_mysql.add_user_feed_item({
            'userid': topic_like['userid'],
            'optype': data_user_feed_mysql.USER_FEED_TYPE_TOPIC_LIKE,
            'targetid': topic_like['topicid'],
        })

if __name__ == '__main__':
    refresh()